package com.zzyl.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class NursingLevelServiceimpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;


    @Override
    public List<NursingLevelVo> listAll() {
        List<NursingLevelVo> list = nursingLevelMapper.listAll();
        list.stream().map(NursingLevelVo -> {
            NursingLevelVo NursingLevelVo1 = new NursingLevelVo();
            BeanUtils.copyProperties(NursingLevelVo, NursingLevelVo1);
            return NursingLevelVo1;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     *添加护理等级
     * @param nursingProjectDto
     */
    @Override
    public void add(NursingLevelDto nursingProjectDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingProjectDto, nursingLevel);
        nursingLevelMapper.add(nursingLevel);

    }

    /**
     * 分页查询护理等级
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> PageNursing(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevel> page = nursingLevelMapper.PageLevel(name, status);
        return PageResponse.of(page, NursingLevelVo.class);
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @Override
    public NursingLevelVo getById(Long id) {
      return   nursingLevelMapper.getById(id);
    }

    /**
     * 修改护理等级
     * @param nursingProjectDto
     */
    @Override
    public void update(NursingLevelDto nursingProjectDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingProjectDto, nursingLevel);
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevel.setUpdateBy(1l);
        nursingLevelMapper.update(nursingLevel);
    }

    /**
     * 删除护理等级
     * @param id
     */
    @Override
    public void delete(Long id) {
         nursingLevelMapper.delete(id);
    }

    /**
     * 启用/禁用护理项目
     * @param id
     * @param status
     */
    @Override
    public void modifyState(Long id, Integer status) {
        nursingLevelMapper.modifyState(id, status);
    }
}
